home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LT_InitExit.c < prev    next >
C/C++ Source or Header  |  1996-08-22  |  5KB  |  231 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /****** gtlayout.library/LT_Init ******************************************
  15. *
  16. *   NAME
  17. *    LT_Init -- Initialize user interface code.
  18. *
  19. *   SYNOPSIS
  20. *    LT_Init();
  21. *
  22. *    VOID LT_Init(VOID);
  23. *
  24. *   FUNCTION
  25. *    You need to initialize the user interface code only once,
  26. *    so it can set up its internals, open libraries, etc.
  27. *    The code has to be initialized before any user interface
  28. *    creation can take place.
  29. *
  30. *   NOTES
  31. *    This function is not present in the shared library, only
  32. *    in the link library. You need not and cannot invoke it in
  33. *    the shared library.
  34. *
  35. *   SEE ALSO
  36. *    gtlayout.library/LT_Exit
  37. *
  38. ******************************************************************************
  39. *
  40. */
  41.  
  42. BOOL LIBENT
  43. LT_Init()
  44. {
  45. #ifndef LINK_LIB
  46.     SysBase = *(struct ExecBase **)4;
  47. #endif    // LINK_LIB
  48.  
  49.     if(SysBase->LibNode.lib_Version < 37)
  50.         return(FALSE);
  51.     else
  52.     {
  53.         STATIC struct { STRPTR Name; APTR *Library; } InitTable[] =
  54.         {
  55.             "intuition.library",    (APTR *)&IntuitionBase,
  56.             "graphics.library",        (APTR *)&GfxBase,
  57.             "utility.library",        (APTR *)&UtilityBase,
  58.             "gadtools.library",        (APTR *)&GadToolsBase,
  59.             "keymap.library",        (APTR *)&KeymapBase,
  60.             "locale.library",        (APTR *)&LocaleBase
  61.         };
  62.  
  63.         STATIC struct { STRPTR ClassName; LONG Size; HOOKFUNC Dispatcher; Class **ClassPtr; } ClassInitTable[] =
  64.         {
  65.             IMAGECLASS,        sizeof(ImageInfo),        (HOOKFUNC)LTP_ImageDispatch,        <P_ImageClass,
  66.  
  67. #ifdef DO_LEVEL_KIND
  68.             IMAGECLASS,        sizeof(LevelImageInfo),    (HOOKFUNC)LTP_LevelClassDispatcher,    <P_LevelClass,
  69. #endif    /* DO_LEVEL_KIND */
  70.  
  71. #if defined(DO_POPUP_KIND) && defined(DO_BOOPSI_KIND)
  72.             GADGETCLASS,    sizeof(PopInfo),        (HOOKFUNC)LTP_PopupClassDispatcher,    <P_PopupClass,
  73. #endif    /* DO_POPUP_KIND */
  74.  
  75. #if defined(DO_TAB_KIND) && defined(DO_BOOPSI_KIND)
  76.             GADGETCLASS,    sizeof(TabInfo),        (HOOKFUNC)LTP_TabClassDispatcher,    <P_TabClass,
  77. #endif    /* DO_TAB_KIND */
  78.  
  79.         };
  80.  
  81.         LONG i;
  82.  
  83.         V39 = (SysBase->LibNode.lib_Version >= 39);
  84.         V40 = (SysBase->LibNode.lib_Version >= 40);
  85.  
  86.         for(i = 0 ; i < NUMELEMENTS(InitTable) ; i++)
  87.             *InitTable[i].Library = OpenLibrary(InitTable[i].Name,37);
  88.  
  89.         if(IntuitionBase && GfxBase && UtilityBase && GadToolsBase && KeymapBase)
  90.         {
  91.             if(LocaleBase)
  92.                 LTP_Locale = OpenLocale(NULL);
  93.  
  94.             for(i = 0 ; i < NUMELEMENTS(ClassInitTable) ; i++)
  95.             {
  96.                 if(*ClassInitTable[i].ClassPtr = MakeClass(NULL,ClassInitTable[i].ClassName,NULL,ClassInitTable[i].Size,0))
  97.                     (*ClassInitTable[i].ClassPtr)->cl_Dispatcher.h_Entry = ClassInitTable[i].Dispatcher;
  98.                 else
  99.                 {
  100.                     LT_Exit();
  101.                     return(FALSE);
  102.                 }
  103.             }
  104.  
  105. #ifdef DO_PICKSHORTCUTS
  106.             InitSemaphore(<P_KeySemaphore);
  107.  
  108.             if(!(LTP_Keys[0] = (UBYTE *)AllocMem(512,MEMF_ANY|MEMF_CLEAR)))
  109.             {
  110.                 LT_Exit();
  111.                 return(FALSE);
  112.             }
  113. #endif    /* DO_PICKSHORTCUTS */
  114.  
  115.             InitSemaphore(<P_LockSemaphore);
  116.  
  117.             NewList((struct List *)<P_LockList);
  118.             NewList((struct List *)<P_EmptyList);
  119.  
  120.             return(TRUE);
  121.         }
  122.  
  123.         LT_Exit();
  124.         return(FALSE);
  125.     }
  126. }
  127.  
  128.  
  129. /*****************************************************************************/
  130.  
  131.  
  132. /****** gtlayout.library/LT_Exit ******************************************
  133. *
  134. *   NAME
  135. *    LT_Exit -- Clean up user interface allocations
  136. *
  137. *   SYNOPSIS
  138. *    LT_Exit();
  139. *
  140. *    VOID LT_Exit(VOID);
  141. *
  142. *   FUNCTION
  143. *    When you are finished with user interface creation and
  144. *    do not not need the code any more you should call this
  145. *    routine. It will free all the memory allocated by
  146. *    LT_Init(), close libraries, etc.
  147. *
  148. *   INPUTS
  149. *    none
  150. *
  151. *   RESULT
  152. *    none
  153. *
  154. *   NOTES
  155. *    This function is not present in the shared library, only
  156. *    in the link library. You need not and cannot invoke it in
  157. *    the shared library.
  158. *
  159. *   SEE ALSO
  160. *    gtlayout.library/LT_Init
  161. *
  162. ******************************************************************************
  163. *
  164. */
  165.  
  166. VOID LIBENT
  167. LT_Exit()
  168. {
  169.     if(SysBase && SysBase->LibNode.lib_Version >= 37)
  170.     {
  171. #ifdef DO_PICKSHORTCUTS
  172.         FreeMem(LTP_Keys[0],512);
  173.         LTP_Keys[0] = LTP_Keys[1] = NULL;
  174. #endif
  175.  
  176. #ifdef DO_LEVEL_KIND
  177.         if(LTP_LevelClass)
  178.         {
  179.             FreeClass(LTP_LevelClass);
  180.             LTP_LevelClass = NULL;
  181.         }
  182. #endif    /* DO_LEVEL_KIND */
  183.  
  184. #if defined(DO_POPUP_KIND) && defined(DO_BOOPSI_KIND)
  185.         if(LTP_PopupClass)
  186.         {
  187.             FreeClass(LTP_PopupClass);
  188.             LTP_PopupClass = NULL;
  189.         }
  190. #endif    // DO_POPUP_KIND
  191.  
  192. #if defined(DO_TAB_KIND) && defined(DO_BOOPSI_KIND)
  193.         if(LTP_TabClass)
  194.         {
  195.             FreeClass(LTP_TabClass);
  196.             LTP_TabClass = NULL;
  197.         }
  198. #endif    // DO_TAB_KIND
  199.  
  200.         if(LTP_ImageClass)
  201.         {
  202.             FreeClass(LTP_ImageClass);
  203.             LTP_ImageClass = NULL;
  204.         }
  205.  
  206.         if(LTP_Locale)
  207.         {
  208.             CloseLocale(LTP_Locale);
  209.             LTP_Locale = NULL;
  210.         }
  211.  
  212.         CloseLibrary(LocaleBase);
  213.         LocaleBase = NULL;
  214.  
  215.         CloseLibrary(KeymapBase);
  216.         KeymapBase = NULL;
  217.  
  218.         CloseLibrary(GadToolsBase);
  219.         GadToolsBase = NULL;
  220.  
  221.         CloseLibrary(UtilityBase);
  222.         UtilityBase = NULL;
  223.  
  224.         CloseLibrary(GfxBase);
  225.         GfxBase = NULL;
  226.  
  227.         CloseLibrary(IntuitionBase);
  228.         IntuitionBase = NULL;
  229.     }
  230. }
  231.